package com.tea.config.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 阿里云OSS配置类
 * @author tea-shop
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "aliyun.oss", name = "enabled", havingValue = "true")
public class OssConfig {
    
    @Resource
    private OssProperties ossProperties;
    
    /**
     * 创建OSS客户端
     * @return OSS客户端实例
     */
    @Bean
    public OSS ossClient() {
        log.info("正在初始化阿里云OSS客户端...");
        
        // 创建OSS客户端
        OSS ossClient = new OSSClientBuilder()
                .build(ossProperties.getEndpoint(), 
                       ossProperties.getAccessKeyId(), 
                       ossProperties.getAccessKeySecret());
        
        log.info("阿里云OSS客户端初始化完成，Endpoint: {}, Bucket: {}", 
                ossProperties.getEndpoint(), ossProperties.getBucketName());
        
        return ossClient;
    }
}